#include <iostream>
#include <vector>
#include <iomanip>
#include <random>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <map>
#include <functional>

std::map<std::string, std::string> parse_args(int argc, char **argv) {
    std::map<std::string, std::string> ret;
    std::string key;
    for (int i = 1; i < argc; ++i) {
        std::string s = argv[i];
        if (s.find("-") == 0) {
            key = s.substr(1);
            ret[key] = " ";
            continue;
        }
        if (!key.empty()) {
            ret[key] = s;
            key.clear();
            continue;
        }
    }
    return std::move(ret);
}

template<class T>
bool convert_if_present(const std::string &input, T *output) {
    if (input.empty()) {
        return false;
    }
    std::stringstream ss;
    ss << input;
    ss >> (*output);
    return true;
}

std::string fixed_len_str(float f, int len) {
    std::stringstream ss;
    ss << std::setiosflags(std::ios::fixed) << std::setprecision(len) << f;
    return ss.str();
}

std::string convert_fv_in_game(float f) {
    return fixed_len_str(f, 9);
}

std::string convert_fv_at_buff(float f) {
    std::string r = fixed_len_str(f, 17);
    std::stringstream ss;
    ss << std::setprecision(17) << f;
    std::string r2 = ss.str();
    if (r2.size() < r.size()) {
        return r2;
    }
    return r;
}

int main(int argc, char **argv) {
    std::map<std::string, std::string> args = parse_args(argc, argv);

    int max_tries = 10;
    convert_if_present(args["t"], &max_tries);
    std::cerr << "# max_tries=" << max_tries << std::endl;

    float target_low = 0.f;
    convert_if_present(args["l"], &target_low);
    std::cerr << "# target_low=" << target_low << std::endl;

    float target_high = 1.f;
    convert_if_present(args["h"], &target_high);
    std::cerr << "# target_high=" << target_high << std::endl;

    std::vector<std::function<bool(float, const std::string &, const std::string &)>> rules;
    if (!args["min"].empty()) {
        float min = std::stof(args["min"]);
        std::cerr << "# rule:min=" << min << std::endl;
        rules.push_back([min](float f, const std::string &fv_in_game, const std::string &fv_at_buff) {
            return f >= min;
        });
    }
    if (!args["max"].empty()) {
        float max = std::stof(args["max"]);
        std::cerr << "# rule:max=" << max << std::endl;
        rules.push_back([max](float f, const std::string &fv_in_game, const std::string &fv_at_buff) {
            return f <= max;
        });
    }
    if (!args["maxlen"].empty()) {
        int maxlen = std::stoi(args["maxlen"]);
        std::cerr << "# rule:maxlen=" << maxlen << std::endl;
        rules.push_back([maxlen](float f, const std::string &fv_in_game, const std::string &fv_at_buff) {
            return fv_at_buff.size() <= maxlen;
        });
    }
    if (!args["without"].empty()) {
        std::string arg_without = args["without"];
        std::cerr << "# rule:without=" << arg_without << "[" << arg_without.size() << std::endl;
        rules.push_back([arg_without](float f, const std::string &fv_in_game, const std::string &fv_at_buff) {
            return fv_at_buff.find_first_of(arg_without) == std::string::npos;
        });
    }
    if (!args["has"].empty()) {
        std::string arg_has = args["has"];
        std::cerr << "# rule:has=" << arg_has << "[" << arg_has.size() << std::endl;
        rules.push_back([arg_has](float f, const std::string &fv_in_game, const std::string &fv_at_buff) {
            return fv_at_buff.find(arg_has) != std::string::npos;
        });
    }
    std::cerr << "# rules=" << rules.size() << std::endl;
    auto check_rules = [&rules](float f, const std::string &fv_in_game, const std::string &fv_at_buff) {
        for (auto &r : rules) {
            if (!r(f, fv_in_game, fv_at_buff)) {
                return false;
            }
        }
        return true;
    };

    std::map<float, int> indexes;
    std::vector<float> fs;
    float tmp_f;
    int line = 0;
    while (std::cin >> tmp_f) {
        ++line;
        indexes[tmp_f] = line;
        if (tmp_f == 0.f) {
            continue;
        }
        fs.push_back(tmp_f);
    }
    if (fs.size() < 10) {
        std::cerr << "! Input size error: " << fs.size() << std::endl;
        return 1;
    }
    std::cout << "# input_size: " << fs.size() << std::endl;

    std::random_device rd;
    std::mt19937 g(rd());
    int loops_per_try = 1000000;

    std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(20);

    for (int i = 0; i < loops_per_try * max_tries; ++i) {
        if (i % loops_per_try == 0) {
            std::cout << "# loops: " << i << std::endl;
        }

        std::shuffle(fs.begin(), fs.end(), g);

        float s = 0.f;
        for (int j = 0; j < 10; ++j) {
            s += fs[j];
        }
        s /= 10.f;
        s = target_low + (target_high - target_low) * s;

        std::string fv_in_game = convert_fv_in_game(s);
        std::string fv_at_buff = convert_fv_at_buff(s);

        if (check_rules(s, fv_in_game, fv_at_buff)) {
            for (int j = 0; j < 10; ++j) {
                std::cout << fs[j] << " [" << indexes[fs[j]] << std::endl;
            }
            std::cout << "# fv_in_game: " << fv_in_game << std::endl;
            std::cout << "# fv_at_buff: " << fv_at_buff << std::endl;
            break;
        }
    }

    return 0;
}
